package com.snl.micro.blog.article.dao.repository.impl;

import com.snl.micro.blog.article.dao.mapper.ArticleMapper;
import com.snl.micro.blog.article.dao.repository.ArticleRepository;
import com.snl.micro.blog.article.pojo.po.ArticlePo;
import com.snl.micro.blog.common.query.ArticleQueryParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class ArticleRepositoryImplement implements ArticleRepository {

    @Autowired
    private ArticleMapper articleMapper;
    @Override
    public void insertArticle(ArticlePo po) {
        log.debug("参数：{}",po);
        articleMapper.insertArticle(po);
    }

    @Override
    public List<ArticlePo> query(ArticleQueryParam queryParam) {
        Integer pageSize = queryParam.getPageSize();
        Integer currentPage = queryParam.getCurrentPage();
        if (pageSize != null && currentPage != null) {
        currentPage = (currentPage-1) * pageSize;
        }
        queryParam.setCurrentPage(currentPage);
        return articleMapper.query(queryParam);
    }

    @Override
    public Long selectAllArticles(ArticleQueryParam queryParam) {
        return articleMapper.selectAllArticlesByUserId(queryParam);
    }
}
